setwd("/Users/ykim/Desktop/ISDS/")

### Figure 1. ISDS Risk

par(mfrow=c(1,2))

dem=seq(-10,10,0.1)
dem2=dem^2
rol=((dem+10)^2)/400
tpr=1-rol
rgr=(dem+10-10*rol)/10
isd=tpr+rgr

plot(dem,tpr,type="l",ylim=c(0,1.8),xlab="Democracy",ylab="",axes=F)
axis(side=1,at=c(-10,0,10),labels=c(-10,0,10))
title(main="Two types of risk")
par(new=T)
plot(dem,rgr,type="l",ylim=c(0,1.8),xlab="",ylab="",axes=F)
text(-8,1.15,"Traditional risk",cex=0.7)
text(8,1.15,"Regulatory risk",cex=0.7)
plot(dem,isd,type="l",ylim=c(0,1.8),xlab="Democracy",ylab="",axes=F)
axis(side=1,at=c(-10,0,10),labels=c(-10,0,10))
title(main="ISDS risk")

### Figure 2. Marginal effects of Democracy

par(mfrow=c(2,2))

logit=read.csv("polity2.csv",sep=",")
ll=-16
ul=4
cl=ul-(ul-ll)/2
ce=0.5
plot(logit$lno,logit$est_polity2,type="l",lwd=1.5,ylim=c(-ce,ce),xlim=c(ll,ul),xlab="Polity Score",ylab="",axes=F)
title(main="Polity2")
axis(side=1,at=c(ll,cl,ul),labels=c("-10","0","10"))
axis(side=2,at=c(-ce,0,ce),labels=c("-0.5","0","0.5"))
par(new=T)
plot(logit$lno,logit$ll95_polity2,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
par(new=T)
plot(logit$lno,logit$ul95_polity2,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
lines(c(ll-1,ul+1),c(0,0),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce,-ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce,ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce/2,-ce/2),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce/2,ce/2),lty="dotted",lwd=0.1)

logit=read.csv("freedom.csv",sep=",")
ll=-4.1
ul=1.9
cl=ul-(ul-ll)/2
ce=1.5
plot(logit$lno,logit$est_freedom,type="l",lwd=1.5,ylim=c(-ce,ce),xlim=c(ll,ul),xlab="Freedom",ylab="",axes=F)
title(main="Freedom")
axis(side=1,at=c(ll,cl,ul),labels=c("0","3","6"))
axis(side=2,at=c(-ce,0,ce),labels=c("-1.5","0","1.5"))
par(new=T)
plot(logit$lno,logit$ll95_freedom,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
par(new=T)
plot(logit$lno,logit$ul95_freedom,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
lines(c(ll-1,ul+1),c(0,0),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce,-ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce,ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce/2,-ce/2),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce/2,ce/2),lty="dotted",lwd=0.1)

logit=read.csv("liec.csv",sep=",")
ll=-5.7
ul=0.3
cl=ul-(ul-ll)/2
ce=3
plot(logit$lno,logit$est_liec,type="l",lwd=1.5,ylim=c(-ce,ce),xlim=c(ll,ul),xlab="LIEC",ylab="",axes=F)
title(main="LIEC")
axis(side=1,at=c(ll,cl,ul),labels=c("1","4","7"))
axis(side=2,at=c(-ce,0,ce),labels=c("-3","0","3"))
par(new=T)
plot(logit$lno,logit$ll95_liec,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
par(new=T)
plot(logit$lno,logit$ul95_liec,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
lines(c(ll-1,ul+1),c(0,0),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce,-ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce,ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce/2,-ce/2),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce/2,ce/2),lty="dotted",lwd=0.1)

logit=read.csv("vna.csv",sep=",")
ll=-2.22
ul=1.83
cl=ul-(ul-ll)/2
ce=5
plot(logit$lno,logit$est_vna,type="l",lwd=1.5,ylim=c(-ce,ce),xlim=c(ll,ul),xlab="V&A",ylab="",axes=F)
title(main="Voice & Accountability")
axis(side=1,at=c(ll,cl,ul),labels=c("-2.22","-0.195","1.83"))
axis(side=2,at=c(-ce,0,ce),labels=c("-5","0","5"))
par(new=T)
plot(logit$lno,logit$ll95_vna,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
par(new=T)
plot(logit$lno,logit$ul95_vna,type="l",lty="dashed",lwd=1.5,xlab="",ylab="",ylim=c(-ce,ce),xlim=c(ll,ul),axes=F)
lines(c(ll-1,ul+1),c(0,0),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce,-ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce,ce),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(-ce/2,-ce/2),lty="dotted",lwd=0.1)
lines(c(ll-1,ul+1),c(ce/2,ce/2),lty="dotted",lwd=0.1)

### Figure 3. Predicted Probabilities of Investor-State Dispute

par(mfrow=c(1,1))

d=seq(-10,10,1)
p=c(-4.798297,-4.399045,-4.03638,-3.710301,-3.420807,-3.1679,-2.951579,-2.771845,-2.628696,-2.522133,-2.452157,-2.418766,-2.421962,-2.461743,-2.538111,-2.651065,-2.800605,-2.986732,-3.209444,-3.468742,-3.764627)
ll=c(-6.853043,-6.176975,-5.572552,-5.041099,-4.583502,-4.199461,-3.886546,-3.639549,-3.450795,-3.311449,-3.213103,-3.148892,-3.11398,-3.105763,-3.124256,-3.173304,-3.263486,-3.416501,-3.662416,-4.017732,-4.474255)
ul=c(-2.743551,-2.621116,-2.500207,-2.379502,-2.258113,-2.136339,-2.016613,-1.90414,-1.806596,-1.732817,-1.69121,-1.688641,-1.729944,-1.817724,-1.951967,-2.128827,-2.337724,-2.556962,-2.756472,-2.919752,-3.054999)
plot(d,p,type="l",lwd=1.5,ylim=c(-9,-0.4),xlab="Polity Score",ylab="Probability",axes=F)
title(main="Predicted Probabilities")
axis(side=1,at=c(-10,-5,0,5,10),labels=c("-10","-5","0","5","10"))
axis(side=2,at=c(-9,-4.8,-0.4),labels=c("0","0.1","0.2"))
par(new=T)
plot(d,ll,type="l",lwd=1.5,lty="dashed",xlab="",ylab="",ylim=c(-9,-0.4),axes=F)
par(new=T)
plot(d,ul,type="l",lwd=1.5,lty="dashed",xlab="",ylab="",ylim=c(-9,-0.4),axes=F)
lines(c(-11,11),c(-4.8,-4.8),lty="dotted",lwd=0.1)
lines(c(-11,11),c(-2.7,-2.7),lty="dotted",lwd=0.1)
lines(c(-11,11),c(-6.9,-6.9),lty="dotted",lwd=0.1)
lines(c(-11,11),c(-9,-9),lty="dotted",lwd=0.1)
lines(c(-11,11),c(-0.4,-0.4),lty="dotted",lwd=0.1)
